from google.appengine.ext import db

class UserInfo(db.Model):
    des = db.StringProperty()
    email = db.EmailProperty()
    created = db.DateTimeProperty(auto_now_add=True)
    updated = db.DateTimeProperty(auto_now=True)
    others = db.TextProperty()
class User(db.Model):
    username = db.StringProperty(required=True)
    password = db.StringProperty(required=True)
    name = db.StringProperty()
    type = db.IntegerProperty(default=1)
    info = db.ReferenceProperty(UserInfo)

class ResourceInfo(db.Model):
    des = db.TextProperty()
    url = db.StringProperty()
    text = db.TextProperty()
    data = db.StringProperty()
    created = db.DateTimeProperty(auto_now_add=True)
    updated = db.DateTimeProperty(auto_now=True)
    others = db.TextProperty()
class Resource(db.Model):
    name = db.StringProperty(required=True)
    uuid = db.StringProperty(required=True)
    user = db.ReferenceProperty(User)
    type = db.IntegerProperty(default=1)
    info = db.ReferenceProperty(ResourceInfo)

class ClientInfo(db.Model):
    ip = db.StringProperty()
    browser = db.StringProperty()
    os = db.StringProperty()
    session = db.StringProperty()
    reference_url = db.StringProperty()
    location = db.StringProperty()
    query = db.StringProperty()
    data = db.TextProperty()
    others = db.TextProperty()
    
class AccessLog(db.Model):
    resource = db.ReferenceProperty(Resource)
    client_info = db.ReferenceProperty(ClientInfo)
    user = db.ReferenceProperty(User)